<?php

namespace App\Models\Invoice;

use App\Models\BaseModel;
use App\Models\Traits\KfSoftDeletes;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Relations\HasMany;

class InvoiceHistoryModel extends BaseModel
{
    use HasFactory, KfSoftDeletes;

    protected $table = "invoice_history";

    protected $fillable = [
        "newInvoiceId",
        "errorMsg",
        "redConfirmSerialNo",
        "redConfirmNo",
        "redConfirmUuid",
        "redConfirmState",
        "blueInvoiceFile",
        "redInvoiceFile",
        "updatedAt",
        "updatedByUid",
        "createdByUid",
        "createdAt"
    ];

    const HEADER_TYPE_0 = 0;
    const HEADER_TYPE_1 = 1;
    //抬头类型
    const HEADER_TYPE_TEXT = [
        self::HEADER_TYPE_0 => "个人",
        self::HEADER_TYPE_1 => "企业",
    ];

    const INVOICE_TYPE_0 = 0;
    const INVOICE_TYPE_1 = 1;
    //发票类型
    const INVOICE_TYPE_TEXT = [
        self::INVOICE_TYPE_0 => "普通发票",
        self::INVOICE_TYPE_1 => "专用发票",
    ];

    //发票字段映射
    const INVOICE_TEMPLATE_TYPE_TEXT = [
        self::INVOICE_TYPE_0 => "02",
        self::INVOICE_TYPE_1 => "01",
    ];

    const STATUS_1    = 1;
    const STATUS_2    = 2;
    const STATUS_3    = 3;
    const STATUS_4    = 4;
    const STATUS_5    = 5;
    const STATUS_TEXT = [
        self::STATUS_1 => "待开票",
        self::STATUS_2 => "开票失败",
        self::STATUS_3 => "已开票",
        self::STATUS_4 => "红冲中",
        self::STATUS_5 => "已红冲",
    ];

    const INVALID_STATUS_1    = 1;
    const INVALID_STATUS_2    = 2;
    const INVALID_STATUS_3    = 3;
    const INVALID_STATUS_TEXT = [
        self::INVALID_STATUS_1 => "作废中",
        self::INVALID_STATUS_2 => "作废失败",
        self::INVALID_STATUS_3 => "作废成功",
    ];

    const BUSINESS_TYPE_1    = 1;
    const BUSINESS_TYPE_2    = 2;
    const BUSINESS_TYPE_TEXT = [
        self::BUSINESS_TYPE_1 => "订货订单",
        self::BUSINESS_TYPE_2 => "软装订单",
    ];

    const CHANNEL_AUTO    = 1;
    const CHANNEL_HISTORY = 2;
    //开票渠道
    const CHANNEL_TYPE_TEXT = [
        self::CHANNEL_AUTO    => "自助开票",
        self::CHANNEL_HISTORY => "财务开票",
    ];

//    const RED_CHANNEL_1 = 1;
//    const RED_CHANNEL_2 = 2;
//    //红冲渠道
//    const RED_CHANNEL_TEXT = [
//        self::RED_CHANNEL_1 => "app",
//        self::RED_CHANNEL_2 => "web",
//    ];

    // 飞书通知状态
    const FS_NOTICE_STATUS_1         = 1;
    const FS_NOTICE_STATUS_2         = 2;
    const FS_NOTICE_STATUS_3         = 3;
    const FS_NOTICE_STATUS_4         = 4;
    const FS_NOTICE_STATUS_TEXT      = [
        self::FS_NOTICE_STATUS_1 => "开票成功",
        self::FS_NOTICE_STATUS_2 => "开票失败",
        self::FS_NOTICE_STATUS_3 => "红冲成功",
        self::FS_NOTICE_STATUS_4 => "红冲失败",
    ];
    const FS_NOTICE_STATUS_DESC_TEXT = [
        self::FS_NOTICE_STATUS_1 => "申请开票成功",
        self::FS_NOTICE_STATUS_2 => "开票失败",
        self::FS_NOTICE_STATUS_3 => "开具的发票红冲成功",
        self::FS_NOTICE_STATUS_4 => "开具的发票红冲失败",
    ];
    const FS_NOTICE_STATUS_COLOR     = [
        self::FS_NOTICE_STATUS_1 => "blue",
        self::FS_NOTICE_STATUS_2 => "red",
        self::FS_NOTICE_STATUS_3 => "blue",
        self::FS_NOTICE_STATUS_4 => "red",
    ];

    /**
     * @return HasMany
     */
    public function businessRel(): HasMany
    {
        return $this->hasMany(InvoiceHistoryBusinessRelModel::class, "invoiceHistoryId", "id");
    }

    /**
     * @return string
     */
    public function getInvoiceTypeTemplateText(): string
    {
        return self::INVOICE_TEMPLATE_TYPE_TEXT[$this->invoiceType];
    }


}
